<template>

  <div>
    <el-container>
      <el-header>
        <Nav1></Nav1>
      </el-header>

      <el-container>
        <MyViewSideBar></MyViewSideBar>
        <el-main class="right-main">
          <ArticleList :ArticleList="ArticleList" :uId="1">

          </ArticleList>

        </el-main>
      </el-container>


    </el-container>
  </div>
</template>

<script>


import {defineComponent} from "vue";
import MyViewSideBar from "@/components/MyView/MyViewSideBar.vue";
import Nav1 from "@/components/nav/Nav1.vue";
import {articleList, articleSelect, userInfo} from "@/utils/api";
import {parseTime} from "../../../public/FormatTime";
import ArticleList from "@/components/ArticleList";
import {articleSelectByUser} from "@/utils/api";

export default defineComponent({
  components: {ArticleList, Nav1, MyViewSideBar},
  data() {
    return {
      user: {
        loginName: '',
        password: '',
        userId: 1

      },
      userInfo: {
        username: '',
        userId: 1,
        genderId: 1,
        qq:'',
        phoneNumber:'',
        email:'',
        introduction: ''
      },

      userId: 0,
      ArticleList: []
    }
  },

  methods: {
    onSubmit() {
      this.$router.push('/changemessage');
    },


    submitSearch() {
      articleSelect(this.articleForm)
          .then((response) => {
            // 处理成功的响应
            console.log('Article submitted successfully!', response);
            this.ArticleList = []
            for (let i = 0; i < response.data.length; i++) {
              response.data[i].createTime = parseTime(response.data[i].createTime)
              this.ArticleList.push(response.data[i]);
            }
          })
          .catch((error) => {
            // 处理错误
            console.error('Error submitting article:', error);
          });
    },
    myArticle() {
      articleSelectByUser(this.userId)
          .then((response) => {
            // 处理成功的响应
            console.log('Article submitted successfully!', response);
            this.ArticleList = []
            for (let i = 0; i < response.data.length; i++) {
              response.data[i].createTime = parseTime(response.data[i].createTime)
              this.ArticleList.push(response.data[i]);
            }
          })
          .catch((error) => {
            // 处理错误
            console.error('Error submitting article:', error);
          });
    },

  },
  mounted(){
    this.userId = sessionStorage.getItem('userId')
    this.myArticle()
  }


})
</script>


<style scoped>
.message {
  width: 100px;
  height: 100px;
  background-color: black;
}
.right-main{
  width: 800px;
  height: 100%;
  margin: 20px auto;
  background-color: #f8f8f8;
}
</style>
